package me.zhengjie.business.service.impl;

import com.alibaba.fastjson.JSONObject;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import me.zhengjie.business.service.ZhsqProService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.persistence.EntityManager;
import javax.persistence.StoredProcedureQuery;

/**
 * @description 执行照护申请
 * @author xiahongbo
 * @date 2022-08-03
 **/
@Slf4j
@Service
@RequiredArgsConstructor
public class ZhsqProServiceImpl implements ZhsqProService {

    @Autowired
    private EntityManager entityManager;

    @Override
    public JSONObject make2901(Long userId, Long zhid) {

        JSONObject object = new JSONObject();
        log.info("机构照护申请--复核 开始 userId:{}, zhid:{}", userId, zhid);

        StoredProcedureQuery storedProcedureQuery = this.entityManager.createNamedStoredProcedureQuery("make2901");

        /**
         * 设置传入参数值
         */
        storedProcedureQuery.setParameter("IR_USER_ID", String.valueOf(userId));
        storedProcedureQuery.setParameter("IR_ZHID", String.valueOf(zhid));
        /**
         * 获取结果出参
         */
        storedProcedureQuery.execute();
        int code = (int) storedProcedureQuery.getOutputParameterValue("OR_APPCODE");
        String msg = (String) storedProcedureQuery.getOutputParameterValue("OR_MESSAGE");

        log.info("机构照护申请-复核 结束 :code:{}，msg:{}", code, msg);
        object.put("code", code);
        object.put("msg", msg);

        return object;
    }
}
